<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Service\Dao;

use App\Model\Area;
use Han\Utils\Service;

class AreaDao extends Service
{
    public function getList($page, $limit): array|bool
    {
        $model = new Area();
        $list = $model::query()->orderByDesc('id')->offset($page - 1 * $limit)->limit($limit)->get();
        if ($list) {
            var_dump($list->toArray());
            return $list->toArray();
        }
        return false;
    }

    public function insert(Area $area): bool
    {
        return $area->save();
    }

    public function update(Area $area): int
    {
        return $area->where('id', $area->id)->update($area->toArray());
    }

    public function getDetail(int $id): Area
    {
        return Area::find($id);
    }
}
